<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <ul>
    <li>西施</li>
    <li>貂蝉</li>
    <li>王昭君</li>
    <li>杨玉环</li>
    <li>芙蓉姐姐</li>
  </ul>
  <script>
    //隔行变色 鼠标进入高亮显示
    var lis = document.querySelectorAll('li');
    for(var i = 0; i<lis.length; i++){
      //隔行变色 
      if(i%2 == 0){
        lis[i].style.backgroundColor = "red";
      }else{
        lis[i].style.backgroundColor = "green";
      }
      //鼠标进入事件
      var bg;
      lis[i].onmouseenter = function(){
        //保存鼠标进入前的颜色
        bg = this.style.backgroundColor;
        this.style.backgroundColor = "yellow";
      }
      //鼠标离开事件
      lis[i].onmouseleave = function(){
        //将鼠标进入前的颜色 设置给鼠标离开后的 li需要显示的背景色
        this.style.backgroundColor = bg;
      }
    }
  </script>
</body>
</html>
